﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="Expenses.Views.MainPage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    IsTabStop="false"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Expenses.Views"
    xmlns:common="using:Expenses.Common"
    xmlns:converters="using:Expenses.Converters"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    GotFocus="MainPage_GotFocus">

    <Page.Resources>
        <ResourceDictionary>
            <CollectionViewSource x:Name="SummaryItemsViewSource"/>
            <CollectionViewSource x:Name="GroupedSummaryItemsViewSource" />

           <DataTemplate x:Key="SummaryItemTemplate">
                <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                      Width="275" 
                      Height="350">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="75"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Key}" 
                               Grid.Row="0"
                               Margin="20,25,20,0" 
                               VerticalAlignment="Top"
                               FontSize="{StaticResource FontSizeLarge}"
                               FontWeight="SemiBold"/>
                    <StackPanel Grid.Row="1">
                        <TextBlock Text="{Binding Summary}" 
                                   Margin="20,0,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"
                                   FontWeight="SemiBold"/>
                        <TextBlock Text="{Binding Details1}" 
                                   Margin="20,30,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details2}" 
                                   Margin="20,30,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details3}" 
                                   Margin="20,30,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details4}" 
                                   Margin="20,30,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>                        
                    </StackPanel>
                </Grid>
            </DataTemplate>

           <DataTemplate x:Key="SnappedSummaryItemTemplate">
                <Grid Background="{StaticResource ItemTemplateBackgroundColor}"
                      Width="250" 
                      Height="275">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="75"/>
                        <RowDefinition Height="*"/>
                    </Grid.RowDefinitions>
                    <TextBlock Text="{Binding Key}" 
                               Grid.Row="0"
                               Margin="20,25,20,0" 
                               VerticalAlignment="Top"
                               FontSize="{StaticResource FontSizeMedium}"
                               FontWeight="SemiBold"/>
                    <StackPanel Grid.Row="1">
                        <TextBlock Text="{Binding Summary}" 
                                   Margin="20,0,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"
                                   FontWeight="SemiBold"/>
                        <TextBlock Text="{Binding Details1}" 
                                   Margin="20,15,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details2}" 
                                   Margin="20,15,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details3}" 
                                   Margin="20,15,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>
                        <TextBlock Text="{Binding Details4}" 
                                   Margin="20,15,20,0" 
                                   VerticalAlignment="Top"
                                   FontSize="{StaticResource FontSizeMedium}"/>                        
                    </StackPanel>
                </Grid>
            </DataTemplate>

        </ResourceDictionary>
    </Page.Resources>

    <Grid x:Name="LayoutRoot" 
          Background="{StaticResource AppBackgroundColor}">
        <Grid.RowDefinitions>
            <RowDefinition Height="140"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border Background="{StaticResource ItemTemplateBackgroundColor}"
                    Grid.Column="1">
                <StackPanel x:Name="PageTitleStackPanel" 
                            Orientation="Horizontal"
                            Margin="120,0,0,0">
                    <TextBlock x:Name="PageTitleTextBlock" 
                               Text="My expenses" 
                               Style="{StaticResource PageHeaderTextStyle}"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Bottom"
                               FontSize="48"
                               Foreground="White"/>
                    <TextBlock x:Name="UserNameTextBlock" 
                               Style="{StaticResource SubheaderTextStyle}"
                               Margin="40,0,0,42"
                               HorizontalAlignment="Left"
                               VerticalAlignment="Bottom"
                               Foreground="White"/>
                </StackPanel>
            </Border>
        </Grid>

        <ProgressRing x:Name="MainPageProgressRing" 
                      Grid.Row="1" 
                      Height="150"
                      Width="150"
                      IsActive="False"/>

        <TextBlock x:Name="NoDataTextBlock" 
                   Grid.Row="1"
                   Text="You have no outstanding charges or active expense reports."
                   Margin="0,100,0,0"
                   Style="{StaticResource SnappedPageHeaderTextStyle}"
                   Foreground="{StaticResource ItemTemplateBackgroundColor}"
                   VerticalAlignment="Top"
                   HorizontalAlignment="Center" 
                   Visibility="Collapsed"/>

        <GridView x:Name="SummaryItemsGridView" 
                  Grid.Row="1"
                  Margin="110,50,0,0"
                  Foreground="White"     
                  SelectionMode="None"
                  IsItemClickEnabled="True"
                  ItemsSource="{Binding Mode=OneWay, Source={StaticResource GroupedSummaryItemsViewSource}}" 
                  ItemTemplate="{StaticResource SummaryItemTemplate}"
                  ItemClick="SummaryItemsGridView_ItemClick">
            <GridView.ItemsPanel>
                <ItemsPanelTemplate>
                    <WrapGrid ItemWidth="275" 
                              ItemHeight="350" 
                              MaximumRowsOrColumns="1" 
                              VerticalChildrenAlignment="Top" />
                </ItemsPanelTemplate>
            </GridView.ItemsPanel>
            <GridView.ItemContainerStyle>
                <Style TargetType="GridViewItem">
                    <Setter Property="Margin" Value="4" />
                    <Setter Property="BorderBrush" Value="Gray" />
                    <Setter Property="BorderThickness" Value="1" />
                    <Setter Property="HorizontalContentAlignment" Value="Center" />
                    <Setter Property="VerticalContentAlignment" Value="Top" />
                </Style>
            </GridView.ItemContainerStyle>
        </GridView>

        <!-- Vertical scrolling list only used when snapped -->
        <ListView x:Name="SummaryItemsListView"
                  AutomationProperties.AutomationId="SummaryItemsListView"
                  AutomationProperties.Name="Grouped Items"
                  Grid.Row="1"
                  Width="500"
                  Visibility="Collapsed"
                  Margin="15,0,0,0"
                  ItemsSource="{Binding Source={StaticResource GroupedSummaryItemsViewSource}}"
                  ItemTemplate="{StaticResource SnappedSummaryItemTemplate}"
                  SelectionMode="None"
                  IsSwipeEnabled="False"
                  IsItemClickEnabled="True"
                  ItemClick="SummaryItemsGridView_ItemClick">
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape"/>
                <VisualState x:Name="Filled"/>

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleStackPanel" 
                                                       Storyboard.TargetProperty="Orientation">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserNameTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleStackPanel" 
                                                       Storyboard.TargetProperty="Orientation">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Vertical"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleStackPanel" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="0,0,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                       <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontSize">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="36"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="FontWeight">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="SemiBold"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PageTitleTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="20,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="UserNameTextBlock" 
                                                       Storyboard.TargetProperty="Margin">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="20,20,0,0"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SummaryItemsGridView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Collapsed"/>
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="SummaryItemsListView" 
                                                       Storyboard.TargetProperty="Visibility">
                            <DiscreteObjectKeyFrame KeyTime="0" 
                                                    Value="Visible"/>
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>

    </Grid>
</common:LayoutAwarePage>
